package cn.wolfcode.trip.base.domain;

import com.alibaba.druid.support.json.JSONUtils;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
/**
 * 大攻略--攻略分类--攻略文章
 */
public class StrategyDetail extends BaseDomain{
    //不发布
    public static final int STATE_NORMAL = 1;
    //发布
    public static final int STATE_RELEASE = 2;

    //标题
    private String title;
    //创建时间
    private Date createTime;
    //发布时间
    private Date releaseTime;
    //序号
    private Integer sequence;
    //攻略分类
    private StrategyCatalog catalog;
    //封面
    private String coverUrl;
    //状态
    private Integer state;
    //拆表 关联攻略文章的内容
    private StrategyContent strategyContent;

    //维护冗余字段
    private Long strategyId;

    public String getStateName(){
        if(state==null){
            return "";
        }
        return state==STATE_NORMAL?"不发布":"发布";
    }

    public String getJSONString(){
        Map<String,Object> map = new HashMap<String,Object>();

        map.put("id",id );
        map.put("title",title );
        map.put("sequence",sequence );
        map.put("coverUrl",coverUrl );
        map.put("state", state);
        map.put("strategyId", strategyId);

        if(catalog!=null){
            map.put("catalogId", catalog.getId());
        }

        return JSONUtils.toJSONString(map);
    }

}